#pragma once

#include "LinkEndData.h"

#include "InputPin.h"
#include "Property.h"
#include "QualifierValue.h"

namespace uml {

LinkEndData::LinkEndData(const QString& umlType)
    : Element(umlType) {}

void LinkEndData::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Element::fromJson(json, errorList);
    end_ = JsonSerializable::create<Property>(json.value("end"), errorList);

    JsonSerializable::fromJsonArray(qualifiers_, "qualifiers", json, errorList);
    value_ = JsonSerializable::create<InputPin>(json.value("value"), errorList);

}

void LinkEndData::toJson(QJsonObject& json) {
    Element::toJson(json);
    if (end_) {
        QJsonObject end_json;
        end_->toJson(end_json);
        json.insert("end", end_json);
    }
    JsonSerializable::toJsonArray(qualifiers_, "qualifiers", json);
    if (value_) {
        QJsonObject value_json;
        value_->toJson(value_json);
        json.insert("value", value_json);
    }
}

/// <summary>
/// allPins
    /// Returns all the InputPins referenced by this LinkEndData. By default this
    /// includes the value and qualifier InputPins, but subclasses may override the
    /// operation to add other InputPins.
/// </summary>
    /// <code>
    /// result = (value->asBag()->union(qualifier.value))
    /// </code>
shared_ptr<vector<InputPin>> LinkEndData::allPins() const
{
    return nullptr;
}

/// <summary>
/// end getter
/// The Association end for which this LinkEndData specifies values.
/// </summary>
shared_ptr<Property> LinkEndData::end() const {
    return end_;
}

/// <summary>
/// end setter
/// The Association end for which this LinkEndData specifies values.
/// </summary>
void LinkEndData::setEnd(shared_ptr<Property> value) {
    end_ = value;
}

/// <summary>
/// qualifiers getter
/// A set of QualifierValues used to provide values for the qualifiers of the end.
/// </summary>
vector<shared_ptr<QualifierValue>>& LinkEndData::qualifiers() {
    return qualifiers_;
}

/// <summary>
/// value getter
/// The InputPin that provides the specified value for the given end. This InputPin
/// is omitted if the LinkEndData specifies the "open" end for a ReadLinkAction.
/// </summary>
shared_ptr<InputPin> LinkEndData::value() const {
    return value_;
}

/// <summary>
/// value setter
/// The InputPin that provides the specified value for the given end. This InputPin
/// is omitted if the LinkEndData specifies the "open" end for a ReadLinkAction.
/// </summary>
void LinkEndData::setValue(shared_ptr<InputPin> value) {
    value_ = value;
}

} // namespace uml
